package com.daxue.tcpweb.controller;

import com.daxue.tcpweb.entity.Question;
import com.daxue.tcpweb.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author daxue0929
 * @date 2022/09/17
 **/
@Controller
public class QuestionController {

    public final QuestionService service;


    @Autowired
    public QuestionController(QuestionService service) {
        this.service = service;
    }

    @RequestMapping("/search")
    @ResponseBody
    public List<Question> searchQuestion(@RequestParam("q") String question) {
        List<Question> list = service.searchQuestion(question);
        return list;
    }

    @RequestMapping("/")
    public String index() {

        return "index";
    }

}
